import 'package:animations/animations.dart';
import 'package:flutter/material.dart';
class PageTransitionSwitcherPage extends StatefulWidget {
  const PageTransitionSwitcherPage({super.key});

  @override
  State<PageTransitionSwitcherPage> createState() => _PageTransitionSwitcherPageState();
}

class _PageTransitionSwitcherPageState extends State<PageTransitionSwitcherPage> {
  bool _showFirst = true;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('PageTransitionSwitcher 示例')),
      body: Center(
        child: PageTransitionSwitcher(
          duration: const Duration(milliseconds: 500),
          reverse: !_showFirst,
          transitionBuilder: (
              Widget child,
              Animation<double> primaryAnimation,
              Animation<double> secondaryAnimation,
              ) {
            return FadeThroughTransition(
              animation: primaryAnimation,
              secondaryAnimation: secondaryAnimation,
              child: child,
            );
          },
          child: _showFirst
              ? Container(
            key: const ValueKey('first'),
            width: 200,
            height: 200,
            color: Colors.blue,
            alignment: Alignment.center,
            child: const Text('页面 A', style: TextStyle(color: Colors.white, fontSize: 24)),
          )
              : Container(
            key: const ValueKey('second'),
            width: 200,
            height: 200,
            color: Colors.green,
            alignment: Alignment.center,
            child: const Text('页面 B', style: TextStyle(color: Colors.white, fontSize: 24)),
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          setState(() {
            _showFirst = !_showFirst;
          });
        },
        child: const Icon(Icons.swap_horiz),
      ),
    );
  }
}